
//获取应用实例
var app = getApp()
var shop;
var number;
Page({

  data: {
    toView: "",
    motto: 'MiHome_Store',
    userInfo: {},
    curNav: 1,
    currentItemId: "1",
    indicatorDots: true,
    interval: 2000,
    interval2: 4500,
    duration: 500,

    // cakes_list: [{
    //     "cakes": [{
    //         "mobile_images": "images/photo.jpg",
    //         "text": "蛋糕"
    //       }],
    //   }],
    // sell: [{
    //   "images": "images/photo.jpg",
    //   "price":'惊爆价：￥10'
    // }]

  },

  onPullDownRefresh: function () {
    wx.showToast({
      title: 'loading...',
      icon: 'loading'
    })
  },

  stopPullDownRefresh: function () {
    wx.stopPullDownRefresh({
      complete: function (res) {
        wx.hideToast()
      }
    })
  },
  
  scroll: function (e) {
    if (this.data.toView == "top") {
      this.setData({
        toView: ""
      })
    }
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  tap: function () {
    this.setData({
      toView: "top"
    })
  },
  //做滑动事件
  changeIndicatorDots1: function (e) {
    this.setData({
      //indicatorDots: !this.data.indicatorDots,
    })
    var number = e.detail.current;
  },

  onShow: function (options){
    
  },

 


// 原页面onload
  onLoad: function (options) {
    var that = this;
    wx.login({
      success: function (res) {
        var that_2 = that;
        if (res.code) {
          // console.log(res.code);console.log("这里是")
          //发起网络请求
          wx.request({
            url: 'https://www.cakeyouxuan.com/small/login/index',
            data: {
              appid: 'wxeb4194dbed5fce65',
              secret: '2436d62d210d8825e0ae456dce1f8911',
              js_code: res.code,
              shopid:31,
            },
            method: "POST",
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function (res) {
              wx.setStorageSync('openid', res.data)
              that_2.setData({
                openid: res.data
              });
              var app = getApp();
              var openid = that_2.data; //openid
              app.whereId.openid = res.data
              var id = app.storeInfo.store;
              var shop = app.storeInfo.store_name;
              app.whereId.shopid = 31;
              var shopid = app.whereId.shopid;
              var avatar = app.globalData.avatar;
              var nickname = app.globalData.nickname;
              var gender = app.globalData.gender;
              wx.request({
                url: 'https://www.cakeyouxuan.com/small/indexskpz/get_uid',
                data: {
                  shopid: 31,
                  openid: app.whereId.openid,
                  avatar: avatar,
                  nickname: nickname,
                  gender: gender,
                },
                method: "POST",
                header: {
                  "Content-Type": "application/x-www-form-urlencoded"
                },
                success: function (res) {
                  app.whereId.uid = res.data;
                  // console.log(res); console.log('123456789');
                },
              })
        },
      })
    } else {
      //console.log('获取用户登录态失败！' + res.errMsg)
    }
  }
});
    //var app = getApp();
    var id = app.storeInfo.store;
    var shop = app.storeInfo.store_name;
    app.whereId.openid = wx.getStorageSync('openid')
    app.whereId.shopid = 31;
    var shopid = app.whereId.shopid;
    var openid = app.whereId.openid;
    var avatar = app.globalData.avatarUrl;
    var nickname = app.globalData.nickName;
    var gender = app.globalData.gender;

    // console.log(openid); console.log('openid');

    wx.request({
      url: 'https://www.cakeyouxuan.com/small/indexskpz/shop',
      data: {
        shopid: 31,
        openid: openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          cakes_list: res.data.mine_list,
          goods_list: res.data.goods_list,
          shop_name: res.data.shop_name,
          banner_list: res.data.banner_list,
          sell: res.data.sell,
        });
      },
    })
  },
  

  //进入商品内页
  stap: function (e) {
    var goods = e.currentTarget.dataset.goods_id.id;
    wx.navigateTo({
      url: "/pages/yiguo/list/list?id=" + goods
    })
  },
  // 热品
  hoter: function (e) {
    var goods = e.currentTarget.dataset.goods_id.id;
    wx.navigateTo({
      url: "/pages/yiguo/list/list?id=" + goods
    })
  },
  
  //店铺简介
  introduce:function(e){
    var ids = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/yiguo/introduce/introduce?ids=" + ids
    })
  },
  
  //一级分类点击进入二级分类
  yiji:function(e){
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: "/pages/yiguo/cakes/cakes?ids=" + id + "&kinds=" + name,
    }) 
  },

});

